function s = subsref(p, S)
% BVQXprogress::subsref  - support for .Progress calls
%
% FORMAT:       pbar.Progress(...);
%
% Input fields:
%
%       pbar        BVQXprogress object

% Version:  v0.8a
% Build:    9102320
% Date:     Oct-23 2009, 8:01 PM CEST
% Author:   Jochen Weber, SCAN Unit, Columbia University, NYC, NY, USA
% URL/Info: http://wiki.brainvoyager.com/BVQXtools

% argument check
if nargin < 2 || ...
    numel(p) ~= 1 || ...
   ~isstruct(S) || ...
   ~isfield(S, 'type') || ...
   ~isfield(S, 'subs') || ...
    isempty(S) || ...
   ~strcmp(S(1).type, '.')
    error( ...
        'BVQXprogress:BadCall', ...
        'Invalid call to BVQXprogress::subsref.' ...
    );
end

% preset output
s = [];

% what call
switch (lower(S(1).subs(:)'))
    case {'close'}
        BVQXprogress(p, 'close', []);
    case {'progress'}
        if numel(S) ~= 2 || ...
           ~strcmp(S(2).type, '()')
            error( ...
                'BVQXprogress:BadCall', ...
                'Invalid .Progress call to object.' ...
            );
        end
        BVQXprogress(p, S(2).subs{:});
    otherwise
        try
            sp = struct(p);
            s = subsref(sp, S(2:end));
        catch
            rethrow(lasterror);
        end
end
